package com.game.server.db.entity;

import java.math.BigDecimal;
import java.sql.Timestamp;
import java.util.*;

import com.game.majiang.config.DataManager;
import com.game.majiang.config.LogManager;
import com.game.majiang.logic.LogicClient;
import com.game.majiang.logic.LogicServer;
import com.game.majiang.logic.LogicTable;
import com.game.majiang.logic.chexuan.ChexuanTabale;
import com.game.server.db.dao.UsersDao;
import com.game.server.db.dao.XyClubContributionLogDao;
import com.game.server.db.dao.XyClubInfoDao;
import com.game.server.db.dao.XyClubJijinLogDao;
import com.game.server.db.dao.XyUnionChangesQuotaDao;
import com.game.server.message.IRespose;
import com.game.server.message.proto.out.TabOutintegralChangeRsp;
import com.game.server.system.AbstractClient;
import com.game.server.system.AbstractRoom;
import com.game.server.system.AbstractTable;
import com.game.server.util.CompuUtils;

import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class XyClubInfo {

    public int id; //俱乐部id
    public int creatorid; //俱乐部创建者ID
    public int unionid; // 联盟ID
    public String name; //俱乐部名称
    public String headurl; //俱乐部头像地址
    public String content; //俱乐部介绍
    public int xingyuvalue;//信誉开关 0关 1开
    public int clubjijin;//俱乐部基金
    public int promotion_type;//推广开关 0 开 1关
    public int unionedu;//联盟的额度
    public Timestamp createdate; //俱乐部创建时间

    private HashMap<Integer, XyClubMemberInfo> player = new HashMap<>();//俱乐部用户

    //定义变量
    private double theContributions = 0.07;//俱乐部贡献比例




    /**
     * 设置bobo 扣除玩家在俱乐部的信誉额度 以及联盟的信誉额度
     * @param bobo
     * @param tabale
     * @param client
     * @return 0 设置成功  1设置失败 2 玩家在俱乐部的信誉额度 3联盟信誉额度不足
     */
    public synchronized int intoTheBobo(int bobo, ChexuanTabale tabale,LogicClient client){
        int backType = 1;
        XyClubMemberInfo xyClubMemberInfo = this.getPlayer().get(client.getUserId());
        System.out.println("俱乐部信誉额度："+xyClubMemberInfo.getXingyuvalue());
        System.out.println("波波："+bobo);
        System.out.println("1波波："+client.getUserId());
        System.out.println("2波波："+this.getUnionid());
        if (xyClubMemberInfo!=null && xyClubMemberInfo.getXingyuvalue()>=bobo){
            XyUnionInfo unionInfo = DataManager.getInstance().getMapUnion().get(this.getUnionid());
            if (unionInfo!=null){
                System.out.println("有联盟的开始口："+unionInfo.getId());
                System.out.println("有联盟的开始口："+tabale.getID());
                System.out.println("有联盟的开始口："+tabale.getTableOnly());
                int updateUnionedu = this.updateUnionedu(3, bobo, unionInfo.getId(), 0, tabale.getID(), tabale.getTableOnly());
                if(updateUnionedu==0){
                    int updateXingyuvalue = xyClubMemberInfo.updateXingyuvalue(3, bobo, tabale.getID(), 0, 0,tabale.getTableOnly());
                    if (updateXingyuvalue==0){
                        backType = 0;
                    }else{
                        backType = 2;
                        this.updateUnionedu(3, -bobo, unionInfo.getId(), 0, tabale.getID(), tabale.getTableOnly());
                    }
                }else{
                    backType = 3;
                }
            }else{
                System.out.println("没有联盟只是俱乐部："+tabale.getTableOnly());
                int updateXingyuvalue = xyClubMemberInfo.updateXingyuvalue(3, bobo, tabale.getID(), 0, 0,tabale.getTableOnly());

                System.out.println("俱乐部扣波波结果："+updateXingyuvalue);
                if(updateXingyuvalue == 0) {
                    backType = 0;
                }else {
                    backType = 2;
                }
            }
        }else{
            backType = 2;
        }
        System.out.println("俱乐部口backType ==bb:"+backType);
        return  backType;
    }

    /**
     * 俱乐部战绩结算
     * @param tableUserInfo 桌子内的玩家信息
     */
    public synchronized void clubRecordSettlement(TableUserInfo tableUserInfo){
        if(tableUserInfo.getTableClubid()==this.id){
            List<TableUser> tableUser = tableUserInfo.getTableUser();

            Map<Integer,Map<Integer,List<TableUser>>> mapListMap = new HashMap<>();
            for (TableUser user : tableUser) {
                mapListMap.put(user.getCid(),null);
            }

            for (Map.Entry<Integer, Map<Integer, List<TableUser>>> mapEntry : mapListMap.entrySet()) {
                Integer key = mapEntry.getKey();
                Map<Integer,List<TableUser>> map = new HashMap<>();//key = 上级合伙人ID 0代表没有上级合伙人
                for (TableUser user : tableUser) {//遍历所有桌子上的玩家
                    if (key.intValue() != user.getCid()){
                        continue;
                    }

                    XyClubInfo clubInfo = DataManager.getInstance().getMapClub().get(user.getCid());
                    if (clubInfo==null){
                        continue;
                    }

                    XyClubMemberInfo xyClubMemberInfo = clubInfo.getPlayer().get(user.getUid());
                    if(xyClubMemberInfo==null || xyClubMemberInfo.getDel_type()==1){
                        continue;
                    }
                    if (xyClubMemberInfo!=null && xyClubMemberInfo.getPid()!=0){//玩家有上级合伙人
                        XyClubMemberInfo proxyMember = clubInfo.getPlayer().get(xyClubMemberInfo.getPid());
                        if (proxyMember!=null && proxyMember.getDel_type()==0){//合伙人未被删除
                            List<TableUser> tableUsers = map.get(proxyMember.getUid());
                            if (tableUsers==null){//将合伙人的下级 放到一起
                                tableUsers = new ArrayList<>();
                                tableUsers.add(user);
                            }else{
                                tableUsers.add(user);
                            }
                            map.put(proxyMember.getUid(),tableUsers);
                        }
                    }else{
                        List<TableUser> tableUsers = map.get(0);
                        if (tableUsers==null){//将合伙人的下级 放到一起
                            tableUsers = new ArrayList<>();
                            tableUsers.add(user);
                        }else{
                            tableUsers.add(user);
                        }
                        map.put(0,tableUsers);
                    }
                }
                mapListMap.put(mapEntry.getKey(),map);
            }

            for (Map.Entry<Integer, Map<Integer, List<TableUser>>> mapEntry : mapListMap.entrySet()) {
                Integer key = mapEntry.getKey();
                Map<Integer, List<TableUser>> map = mapEntry.getValue();
                if (map == null){
                    continue;
                }
                XyClubInfo clubInfo = DataManager.getInstance().getMapClub().get(key.intValue());
                if (clubInfo!=null){
                    for(Map.Entry<Integer,List<TableUser>> entity: map.entrySet()){
                        Integer pid = entity.getKey();
                        List<TableUser> tableUsers = entity.getValue();
                        for (TableUser user : tableUsers) {
                            int win = user.getBalance() - user.getDairu();
                            if (pid==0){
                                if (win>=0){
                                    BigDecimal totalContribution = CompuUtils.multiply(win, clubInfo.theContributions);//俱乐部贡献
                                    int deduct = (int) Math.floor(Double.valueOf(totalContribution.toString()));//扣除比例
//                                    int handBack = win - deduct;//贡献分配

                                    XyClubMemberInfo info = clubInfo.getPlayer().get(user.getUid());
                                    info.updateXingyuvalue(4, (win+user.dairu), tableUserInfo.getTableNo(), 0, 0,tableUserInfo.getGamekey());

                                    info.updateXingyuvalue(5, -deduct, tableUserInfo.getTableNo(), 0, 0,tableUserInfo.getGamekey());
//                                    if (handBack>=0){
//                                        info.updateXingyuvalue(4, (handBack+user.dairu), tableUserInfo.getTableNo(), 0, 0,tableUserInfo.getGamekey());
//                                    }
                                }else{
                                    win = Math.abs(win);
                                    XyClubMemberInfo info = clubInfo.getPlayer().get(user.getUid());
                                    int tuibobo = user.getDairu() - win;
                                    if (tuibobo>0){
                                        info.updateXingyuvalue(4, tuibobo, tableUserInfo.getTableNo(), 0, 0,tableUserInfo.getGamekey());
                                    }
                                }
                            }else{
                                XyClubMemberInfo info = clubInfo.getPlayer().get(user.getUid());
                                if (win>=0){
                                    BigDecimal totalContribution = CompuUtils.multiply(win, clubInfo.theContributions);//俱乐部贡献
                                    int deduct = (int) Math.floor(Double.valueOf(totalContribution.toString()));//扣除比例
//                                    int handBack = win - deduct;//退还贡献
//                                    if (handBack>=0){
//
//                                    }
                                    info.updateXingyuvalue(4, (win+user.dairu), tableUserInfo.getTableNo(), 0, 0,tableUserInfo.getGamekey());
                                    info.updateXingyuvalue(5, -deduct, tableUserInfo.getTableNo(), 0, 0,tableUserInfo.getGamekey());

                                    if (deduct>=0){
                                        BigDecimal divideTheContribution = CompuUtils.multiply(deduct, 0.5);//输家赢家各一半
                                        int half = (int) Math.floor(Double.valueOf(divideTheContribution.toString()));//输家赢家各一半
                                        XyClubMemberInfo proxy = clubInfo.getPlayer().get(pid);
                                        if(proxy.getDel_type()==0 && proxy.getIsAccessory()==1 && half>0){
                                            BigDecimal partnerAcquisitionStr = CompuUtils.multiply(half, Double.valueOf(CompuUtils.divide(proxy.getBonus_share()+"",100+"").toString()));//上级合伙人获得红利
                                            int partnerAcquisition = (int) Math.floor(Double.valueOf(partnerAcquisitionStr.toString()));//合伙人获得
                                            if (partnerAcquisition>0){
                                                proxy.updateBalanceBonus(partnerAcquisition,1,user.getUid(),0);
                                                XyClubContributionLog contributionLog = new XyClubContributionLog();
                                                contributionLog.setCid(clubInfo.id);
                                                contributionLog.setPid(proxy.getUid());
                                                contributionLog.setUid(user.getUid());
                                                contributionLog.setRelevance_id(tableUserInfo.getTableNo());
                                                contributionLog.setIntegral(win);
                                                contributionLog.setProportion(proxy.getBonus_share());
                                                contributionLog.setRoomkey(tableUserInfo.getGamekey());
                                                contributionLog.setVal(partnerAcquisition);

                                                XyClubContributionLogDao.insertInto(contributionLog);
                                                XyClubInfoDao.addDayClubData(user.getUid(),clubInfo.getId(),1,partnerAcquisition,proxy.getUid());
                                                XyClubInfoDao.addDayClubData(user.getUid(),clubInfo.getId(),2,user.getShoushu(),proxy.getUid());
                                            }
                                        }
                                    }
                                }else{
                                    info.updateXingyuvalue(4, (win+user.dairu), tableUserInfo.getTableNo(), 0, 0,tableUserInfo.getGamekey());
                                    win = Math.abs(win);
                                    BigDecimal totalContribution = CompuUtils.multiply(win, clubInfo.theContributions);//俱乐部贡献
                                    int deduct = (int) Math.floor(Double.valueOf(totalContribution.toString()));//扣除比例
                                    if (deduct>=0){
                                        BigDecimal divideTheContribution = CompuUtils.multiply(deduct, 0.5);//输家赢家各一半
                                        int half = (int) Math.floor(Double.valueOf(divideTheContribution.toString()));//输家赢家各一半
                                        XyClubMemberInfo proxy = clubInfo.getPlayer().get(pid);
                                        if(proxy.getDel_type()==0 && proxy.getIsAccessory()==1){
                                            XyClubInfoDao.addDayClubData(user.getUid(),clubInfo.getId(),2,user.getShoushu(),proxy.getUid());
                                            if(half>=0){
                                                BigDecimal partnerAcquisitionStr = CompuUtils.multiply(half, Double.valueOf(CompuUtils.divide(proxy.getBonus_share()+"",100+"").toString()));//上级合伙人获得红利
                                                int partnerAcquisition = (int) Math.floor(Double.valueOf(partnerAcquisitionStr.toString()));//合伙人获得
                                                if (partnerAcquisition>0){
                                                    proxy.updateBalanceBonus(partnerAcquisition,1,user.getUid(),0);

                                                    XyClubContributionLog contributionLog = new XyClubContributionLog();
                                                    contributionLog.setCid(clubInfo.id);
                                                    contributionLog.setPid(proxy.getUid());
                                                    contributionLog.setUid(user.getUid());
                                                    contributionLog.setRelevance_id(tableUserInfo.getTableNo());
                                                    contributionLog.setIntegral(-win);
                                                    contributionLog.setProportion(proxy.getBonus_share());
                                                    contributionLog.setVal(partnerAcquisition);

                                                    XyClubContributionLogDao.insertInto(contributionLog);

                                                    XyClubInfoDao.addDayClubData(user.getUid(),clubInfo.getId(),1,partnerAcquisition,proxy.getUid());
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    /**
     * 将用户添加到俱乐部
     * @param info 用户信息
     * @return
     */
    public boolean addPlayer(XyClubMemberInfo info) {
        if (!this.player.containsKey(info.getUid())) {
            this.player.put(info.getUid(), info);
            return true;
        }
        return false;
    }

    /**
     * 通过合伙人ID获取俱乐部用户
     * @param partnerId
     * @return
     */
    public XyClubMemberInfo findByPartnerId(int partnerId) {
        XyClubMemberInfo clubMemberInfo = new XyClubMemberInfo();

        for (Map.Entry<Integer,XyClubMemberInfo> map : player.entrySet()) {
            if (map.getValue().getPartner_id()==partnerId){
                clubMemberInfo = map.getValue();
                break;
            }
        }
        return clubMemberInfo;
    }

    /**
     * 将用户移除俱乐部
     * @param uid
     * @return
     */
    public synchronized XyClubMemberInfo deletePlayer(int uid) {
        return this.player.remove(uid);
    }

    /**
     * 获取所有俱乐部用户
     * @return
     */
    public synchronized ArrayList<XyClubMemberInfo> getPlayers() {
        return new ArrayList<>(this.player.values());
    }

    /**
     * 获取俱乐部人数
     * @return
     */
    public int getPlayerCount() {
        int count = 0;
        for (Map.Entry<Integer, XyClubMemberInfo> map : player.entrySet()) {
            if (map.getValue().getDel_type()==0){
                count++;
            }
        }
        return count;
    }

    /**
     * 获取合伙人数量
     * @return
     */
    public int getPartnerCount() {
        int count = 0;
        for (Map.Entry<Integer, XyClubMemberInfo> map : player.entrySet()) {
            if (map.getValue().getDel_type()==0 && map.getValue().getIsAccessory()==1){
                count++;
            }
        }
        return count;
    }

    /**
     * 获取合伙人红利余额
     * @return
     */
    public int getPartnerTheBonusBalance() {
        int sum = 0;
        for (Map.Entry<Integer, XyClubMemberInfo> map : player.entrySet()) {
            if (map.getValue().getDel_type()==0 && map.getValue().getIsAccessory()==1){
                sum = sum + map.getValue().getBalance_bonus();
            }
        }
        return sum;
    }
    /**
     * 获取合伙人红利总累计
     * @return
     */
    public long getPartnerDividendsAccumulated() {
        long sum = 0;
        for (Map.Entry<Integer, XyClubMemberInfo> map : player.entrySet()) {
            if (map.getValue().getDel_type()==0 && map.getValue().getIsAccessory()==1){
                sum = sum + map.getValue().getAggregate_bonus();
            }
        }
        return sum;
    }

    /**
     * 获取俱乐部在线人数
     * @return
     */
    public int getOnlineCount() {
        ArrayList<XyClubMemberInfo> players = getPlayers();
        int count = 0;
        for (XyClubMemberInfo clubMemberInfo : players) {
            AbstractClient client = LogicServer.getInstance().getClient(clubMemberInfo.getUid());
            if (client != null && clubMemberInfo.getDel_type()==0) {
                count++;
            }
        }
        return count;
    }

    /**
     * 所有成员额度总量
     * @return
     */
    public Long getTotalContribution() {
        ArrayList<XyClubMemberInfo> players = getPlayers();
        Long contribution = 0L;
        for (XyClubMemberInfo clubMemberInfo : players) {
            if(clubMemberInfo.getDel_type()==0){
                contribution+= Long.valueOf(clubMemberInfo.getXingyuvalue());
            }
        }
        return contribution;
    }

    /**
     * 有额度的人数
     * @return
     */
    public int getNumberOfPeopleWithQuota() {
        ArrayList<XyClubMemberInfo> players = getPlayers();
        int count = 0;
        for (XyClubMemberInfo clubMemberInfo : players) {
            if (clubMemberInfo.getDel_type()==0 && clubMemberInfo.getXingyuvalue()>0){
                count++;
            }
        }
        return count;
    }


    /**
     * 俱乐部基金修改
     * @param pid 操作ID
     * @param uid 被操作者ID
     * @param value
     * @param type 1 充值基金+ 2 发放基金-
     * @return 1失败 0 成功 2余额不足
     */
    public synchronized int updateJiJin(int pid,int uid, Integer value, int type) {
        if (type==1){
            LogicClient client = (LogicClient) LogicServer.getInstance().getClient(pid);
            if (client!=null){
                LogManager.getInstance().Log("操作ID:"+String.valueOf(pid));
                LogManager.getInstance().Log("被操作者ID:"+String.valueOf(uid));
                LogManager.getInstance().Log("积分:"+String.valueOf(client.getVo().getIntegral()));
                if (client.getVo().getIntegral()>=value){
                    int updateCount = XyClubInfoDao.updateJiJin(this.id,value);
                    if (updateCount>0){
                        this.setClubjijin(this.getClubjijin()+value);
                        client.getVo().AddIntegral(-value);
                        client.getVo().getuserinfo(client);
                        XyClubJijinLog log = new XyClubJijinLog();
                        log.setCid(this.id);
                        log.setIntegral(value);
                        log.setPid(pid);
                        log.setUid(uid);
                        log.setResidual_funds(this.getClubjijin());
                        log.setType(type);
                        XyClubJijinLogDao.insertInto(log);
                        LogManager.getInstance().Log("积分22:"+String.valueOf(client.getVo().getIntegral()));
                        return  0;
                    }
                }else{
                    return  2;
                }
            }
        }
        if (type==2){
            if (this.getClubjijin()>=value){
                int updateCount = XyClubInfoDao.updateJiJin(this.id,-value);
                if (updateCount>0){
                    this.setClubjijin(this.getClubjijin()-value);
                    LogicClient client = (LogicClient) LogicServer.getInstance().getClient(uid);
                    if (client!=null){
                        client.getVo().AddIntegral(value);
                        client.getVo().getuserinfo(client);
                        if (client.getTableid()>0){
                            client.getVo().NoticeTabUserXinyuChange(client,1,value);
                        }
                    }else{
                        UsersDao.updateJiFen(uid,value);
                    }
                    XyClubJijinLog log = new XyClubJijinLog();
                    log.setCid(this.id);
                    log.setIntegral(value);
                    log.setPid(pid);
                    log.setUid(uid);
                    log.setResidual_funds(this.getClubjijin());
                    log.setType(type);
                    XyClubJijinLogDao.insertInto(log);
                    return  0;
                }
            }else{
                return  2;
            }
        }
        return  1;
    }

    /**
     * 联盟 俱乐部额度修改
     * @param type 1增加、
     * 2减少、
     * 3带入（带入300 显示-300）、
     * 4结算（最终结算：如果赢了1000 那么身上总bobo应该剩余1300 扣除5%后 这里显示+（）1300*0.05））、
     * 5贡献（这里显示扣除的贡献比例数值）
     * @param value
     * @param unionid
     * @param meUid
     * @param roomid
     * @param roomkey
     * @return
     */
    public int updateUnionedu(Integer type, Integer value, Integer unionid,int meUid, int roomid,long roomkey) {
        XyUnionChangesQuota insertInto = new XyUnionChangesQuota();
        if (type == 1) {
            int upCount = XyClubInfoDao.addUnionedu(this.id, value);
            if (upCount > 0) {
                this.setUnionedu(this.unionedu + value);
                insertInto.setUnid(unionid);
                insertInto.setCid(this.id);
                insertInto.setMe_uid(meUid);
                insertInto.setType(1);
                insertInto.setQuota(value);
                insertInto.setResidue(this.unionedu);
                insertInto.setRoomkey(roomkey);
                XyUnionChangesQuotaDao.insertInto(insertInto);
                return 0;
            }
        }
        if (type == 2) {
            if (this.unionedu >= value) {
                int upCount = XyClubInfoDao.addUnionedu(this.id, -value);
                if (upCount > 0) {
                    this.setUnionedu(this.unionedu - value);
                    insertInto.setUnid(unionid);
                    insertInto.setCid(this.id);
                    insertInto.setMe_uid(meUid);
                    insertInto.setType(2);
                    insertInto.setQuota(-value);
                    insertInto.setResidue(this.unionedu);
                    insertInto.setRoomkey(roomkey);
                    XyUnionChangesQuotaDao.insertInto(insertInto);
                    return 0;
                }
            }else{
                return 2;
            }
        }
        if (type == 3) {
            if (this.unionedu >= value) {
                int upCount = XyClubInfoDao.addUnionedu(this.id, -value);
                if (upCount > 0) {
                    this.setUnionedu(this.unionedu - value);
                    insertInto.setUnid(unionid);
                    insertInto.setCid(this.id);
                    insertInto.setMe_uid(roomid);
                    insertInto.setType(3);
                    insertInto.setQuota(-value);
                    insertInto.setResidue(this.unionedu);
                    insertInto.setRoomkey(roomkey);
                    XyUnionChangesQuotaDao.insertInto(insertInto);
                    return 0;
                }
            }else{
                return 2;
            }
        }
        if (type == 4) {
            int upCount = XyClubInfoDao.addUnionedu(this.id, value);
            if (upCount > 0) {
                this.setUnionedu(this.unionedu + value);
                insertInto.setUnid(unionid);
                insertInto.setCid(this.id);
                insertInto.setMe_uid(roomid);
                insertInto.setType(4);
                insertInto.setQuota(value);
                insertInto.setResidue(this.unionedu);
                insertInto.setRoomkey(roomkey);
                XyUnionChangesQuotaDao.insertInto(insertInto);
                return 0;
            }
        }
        if (type == 5) {
            int upCount = XyClubInfoDao.addUnionedu(this.id, value);
            if (upCount > 0) {
                this.setUnionedu(this.unionedu + value);
                insertInto.setUnid(unionid);
                insertInto.setCid(this.id);
                insertInto.setMe_uid(roomid);
                insertInto.setType(5);
                insertInto.setQuota(value);
                insertInto.setResidue(this.unionedu);
                insertInto.setRoomkey(roomkey);
                XyUnionChangesQuotaDao.insertInto(insertInto);
                return 0;
            }
        }
        return 1;
    }


    /**
     * 获取玩家的俱乐部身份
     * @param uid
     * @return 0 查无此人 1创建者 2管理员 3成员
     */
    public int findPlayerManager(int uid) {
        int type = 0;
        XyClubMemberInfo memberInfo = getPlayer().get(uid);
        if (memberInfo!=null){
            type = memberInfo.getIsManager();
        }
        return  type;
    }

    /**
     * 获取玩家的俱乐部信誉额度
     * @param uid
     * @return 0
     */
    public int findPlayerXinyuValue(int uid) {
        int xinyuvalue = 0;
        XyClubMemberInfo memberInfo = getPlayer().get(uid);
        if (memberInfo!=null){
            xinyuvalue = memberInfo.getXingyuvalue();
        }
        return  xinyuvalue;
    }


    //广播给俱乐部所有用户
    public void broadCastPlayer(IRespose rsp) {
        if (rsp != null) {
            for (XyClubMemberInfo info : getPlayers()) {
                LogicClient client = (LogicClient) LogicServer.getInstance().getClient(info.getUid());
                if (info.getDel_type()==0 && client != null && client.getTableid()==0 && client.getClubid() == this.id) {
                    client.Send(rsp);
                }
            }
        }
    }


    //广播给俱乐部所有管理员以及盟主
    public void broadCastAdminPlayer(IRespose rsp) {
        if (rsp != null) {
            for (XyClubMemberInfo info : getPlayers()) {
                if (info.getDel_type()==0 && (info.getIsManager()==1 || info.getIsManager()==2)){
                    LogicClient client = (LogicClient) LogicServer.getInstance().getClient(info.getUid());
                    if (client != null && client.getTableid()==0 && client.getClubid() == this.id) {
                        client.Send(rsp);
                    }
                }
            }
        }
    }

    public void broadCastAdminDtPlayer(IRespose rsp) {
        if (rsp != null) {
            for (XyClubMemberInfo info : getPlayers()) {
                if (info.getDel_type()==0 && (info.getIsManager()==1 || info.getIsManager()==2)){
                    LogicClient client = (LogicClient) LogicServer.getInstance().getClient(info.getUid());
                    if (client != null && client.getTableid()==0 && client.getClubid() == 0) {
                        client.Send(rsp);
                    }
                }
            }
        }
    }

    //广播给俱乐部大厅的所有用户
    public void broadCastHallPlayer(IRespose rsp) {
        if (rsp != null) {
            for (XyClubMemberInfo info : getPlayers()) {
                LogicClient client = (LogicClient) LogicServer.getInstance().getClient(info.getUid());
                if (info.getDel_type()==0 && client != null && client.getTableid()==0  && client.getTableid() == 0 && client.getClubid() == this.id) {
                    client.Send(rsp);
                }
            }
        }
    }

    public List<LogicTable> findAllTable(int uid,int clubid){
//      UserInfoData userInfoData = DataManager.getInstance().getMapUserData().get(uid);
        List<LogicTable> tabs = new ArrayList<>();
        Collection<AbstractRoom> rooms = LogicServer.getInstance().getRooms();
        for (AbstractRoom room : rooms) {
            ArrayList<AbstractTable> tables = room.getTables();
            for (AbstractTable table : tables) {
                LogicTable tab = (LogicTable) table;
                ChexuanTabale chexuanTab = (ChexuanTabale) tab;
                if (tab.getClubid()==clubid || tab.getUnionid() == unionid){
                    tabs.add(chexuanTab);
                }

//                List<Integer> clubids = userInfoData.getClubids();
//                for (Integer clubid : clubids) {
//                    if (clubid.intValue() != this.id){
//                        continue;
//                    }
//                    XyClubInfo clubInfo = DataManager.getInstance().getMapClub().get(clubid);
//                    if (clubInfo.getUnionid()!=0){
//                        XyUnionInfo unionInfo = DataManager.getInstance().getMapUnion().get(clubInfo.getUnionid());
//                        if (unionInfo!=null){
//                            List<Integer> unionInfoClubids = unionInfo.getClubids();
//                            for (Integer unionInfoClubid : unionInfoClubids) {
//                                if (unionInfoClubid.intValue()!=this.id){
//                                    continue;
//                                }
//                                XyClubInfo unionClubInfo = DataManager.getInstance().getMapClub().get(unionInfoClubid);
//
//                                XyClubMemberInfo memberInfo = unionClubInfo.getPlayer().get(uid);
//                                if (memberInfo!=null && memberInfo.getDel_type()==0){
//                                    tabs.add(chexuanTab);
//                                }
//                            }
//                        }
//                    }
//                }
            }
        }
        return tabs;
    }
}
